from typing import List


class Solution:
    def insert(
        self, intervals: List[List[int]], newInterval: List[int]
    ) -> List[List[int]]:
        intervals.append(newInterval)
        intervals.sort()
        print(intervals, "intervals")
        # for i in range(len(intervals) - 1):
        i = 0
        j = len(intervals) - 1
        while i < j:
            print("i=", i)
            print("intervals", intervals[i])
            next_ = intervals[i + 1]
            current = intervals[i]

            print(next_, current)
            if next_[0] <= current[1]:
                print(i, i + 2)
                intervals[i : i + 2] = [[current[0], max(next_[1], current[1])]]
                print(intervals, "...")
                j -= 1
            else:
                i += 1

        return intervals
